import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig(({ command, mode, ssrBuild }) =>{
  if (command === 'serve') {
    return {
      // dev 独有配置
      plugins: [
        vue(),
      ],
      resolve: {
        alias: {
          '@': fileURLToPath(new URL('./src', import.meta.url))
        }
      },
      server: {
        host: '0.0.0.0',
        proxy: {
          '/apis': {
            target: 'http://localhost:8000/',
            changeOrigin: true,
            // rewrite: (path) => path.replace(/^\/apis/, ''),
          }
        }
      },
    }
  } else {
    // command === 'build'
    return {
      // build 独有配置
      plugins: [
        vue(),
      ],
      resolve: {
        alias: {
          '@': fileURLToPath(new URL('./src', import.meta.url))
        }
      },
    }
  }
  
})
